package com.ydl.shopping.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ydl.shopping.core.entity.BaseEntity;
import com.ydl.shopping.core.valid.ValidGroup;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import java.util.Date;
import java.util.List;

/** 用户表 */
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("tb_user")
@Schema(name = "用户表")
public class TbUser extends BaseEntity {
    /** 用户名 */
    @TableField("username")
    @NotBlank(groups = ValidGroup.Crud.Create.class, message = "用户名不能为空")
    @NotBlank(groups = ValidGroup.Crud.Update.class, message = "用户名不能为空")
    @Schema(description = "用户名")
    private String username;

    /** 手机号 */
    @TableField("tel")
    @Schema(description = "手机号")
    private String tel;

    /** 邮箱 */
    @TableField("email")
    @Schema(description = "邮箱")
    private String email;

    /** 密码 */
    @TableField("password")
    @NotBlank(groups = ValidGroup.Crud.Create.class, message = "密码不能为空")
    @Min(groups = ValidGroup.Crud.Create.class, value = 5, message = "密码长度不能小于5")
    @Schema(description = "密码")
    private String password;

    /** 头像地址 */
    @TableField("icon")
    @Schema(description = "头像地址")
    private String icon;

    /** 用户昵称 */
    @TableField("nickname")
    @Schema(description = "用户昵称")
    private String nickname;

    /** 性别 */
    @TableField("gender")
    @Range(min = 0, max = 2, message = "用户性别 0：保密 1：男，2：女")
    @Schema(description = "性别")
    private Integer gender;

    /** 年龄 */
    @TableField("age")
    @Schema(description = "年龄")
    private Integer age;

    /** 用户类型 0：管理员，1：用户 */
    @TableField("type")
    @Schema(description = "用户类型")
    private Integer type;

    /** 账号状态 0：停用，1：正常 */
    @TableField("status")
    @Schema(description = "账号状态")
    private Integer status;

    /** 用户名最后修改时间 */
    @TableField("username_update_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "用户名最后修改时间")
    private Date usernameUpdateTime; // 用户名修改时间

    /** 是否删除 0：否，1：是 */
    @TableLogic
    @TableField("is_del")
    @Schema(description = "是否删除", hidden = true)
    private Integer isDel;

    /** 角色IDs */
    @TableField(exist = false)
    @Schema(description = "角色IDs")
    private List<Long> roleIds;

    public TbUser() {
    }

    public TbUser(Long id, String nickname, Integer gender, Integer age, String email, String remark) {
        this.setId(id);
        this.nickname = nickname;
        this.gender = gender;
        this.age = age;
        this.email = email;
        this.setRemark(remark);
    }
}
